//arr必须是数组[]，一个参数也必须写成数组形式，原生apply也是如此
Function.prototype.ddApply = function (thisArg, arr) {
  console.log('ddApply执行了')
  var fn = this
  //用于排除thisArg为null或undefined的情况
  thisArg = (thisArg !== null && thisArg !== undefined) ? Object(thisArg) : window
  thisArg.fn = fn
  // arr = arr ? arr : []
  arr = arr || []
  var res = thisArg.fn(...arr)
  delete thisArg.fn
  return res
}

function foo(item1, item2) {
  console.log(this)
  console.log('foo执行了', item1, item2)
  return item1 + item2
}

function bar() {
  console.log('bar执行了')
}

// foo()
var res = foo.ddApply('abc', ['123', '234'])
console.log(res)
bar.ddApply('abc')
